package com.sun.mvc.service;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;

import com.sun.mvc.model.Employee;

@Service
public class EmployeeServiceImpl implements EmployeeService {
	private static Map<String, Employee> employeeMap = new HashMap<>();
	static {
		for (int i = 0; i < 10; i++) {
			String id = UUID.randomUUID().toString();
			Employee emp = new Employee(id, "NAME" + i, i);
			employeeMap.put("NAME" + i, emp);
		}
	}

	@Override
	public List<Employee> getEmployees() {
		return new ArrayList<Employee>(employeeMap.values());
	}

	@Override
	public Employee getEmployeeByName(String userName) {
		return employeeMap.get(userName);
	}

	@Override
	public byte[] getFileByte(String fileId) {
		try {
			File file = new File("C:/upload/4940d9db-7537-4891-99bd-8f322b0be026.docx");
			return FileUtils.readFileToByteArray(file);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new byte[]{};
	}

}
